package com.gmm.springboot.admin.mapper.test02;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface LoginRecordMapper {
	@Select("select * from t_login_record where id=#{id} limit 1 ")
	@Results(value = {

			@Result(property = "id", column = "id"), @Result(property = "userId", column = "user_id"), @Result(property = "ip", column = "ip"),
			@Result(property = "loginTime", column = "login_time") })
	public LoginRecord findRecordByKey(@Param("id") Long id);

	@SelectProvider(method = "getSelectRecordSql", type = LoginRecordSqlProvider.class)
	@Results(value = {

			@Result(property = "id", column = "id"), @Result(property = "userId", column = "user_id"), @Result(property = "ip", column = "ip"),
			@Result(property = "loginTime", column = "login_time") })
	public List<LoginRecord> findSelectRecordByMap(Map<String, Object> whereParams);

	@SelectProvider(type = LoginRecordSqlProvider.class, method = "getSelectCountSql")
	public int findRecordsCount(Map<String, Object> whereParams);

	@Insert("INSERT INTO t_login_record  ( " + " user_id ,  ip ,  login_time " + " )" + " VALUES ( " + " #{userId} ,  #{ip} ,  #{loginTime} " + ")")

	@Options(useGeneratedKeys = true, keyProperty = "id")
	public void addRecord(LoginRecord record);

	@UpdateProvider(type = LoginRecordSqlProvider.class, method = "getUpdateSql")
	public void updRecord(LoginRecord record);

	@Delete("delete from t_login_record where id=#{id}")
	public void delRecord(@Param("id") Long id);
}
